﻿using System;
using System.ComponentModel;

namespace HalconDotNet
{
	/// <summary>Class representing a compute device handle.</summary>
	// Token: 0x0200002A RID: 42
	public class HComputeDevice : HHandle
	{
		// Token: 0x060003AD RID: 941 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HComputeDevice() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x060003AE RID: 942 RVA: 0x00016203 File Offset: 0x00014403
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HComputeDevice(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x060003AF RID: 943 RVA: 0x00016212 File Offset: 0x00014412
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HComputeDevice(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x060003B0 RID: 944 RVA: 0x00016221 File Offset: 0x00014421
		private void AssertSemType()
		{
			base.AssertSemType("compute_device");
		}

		// Token: 0x060003B1 RID: 945 RVA: 0x0001622E File Offset: 0x0001442E
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HComputeDevice obj)
		{
			obj = new HComputeDevice(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x060003B2 RID: 946 RVA: 0x00016248 File Offset: 0x00014448
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HComputeDevice[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HComputeDevice[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HComputeDevice(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Open a compute device.
		///   Modified instance represents: Compute device handle.
		/// </summary>
		/// <param name="deviceIdentifier">Compute device Identifier.</param>
		// Token: 0x060003B3 RID: 947 RVA: 0x000162B8 File Offset: 0x000144B8
		public HComputeDevice(int deviceIdentifier)
		{
			IntPtr proc = HalconAPI.PreCall(304);
			HalconAPI.StoreI(proc, 0, deviceIdentifier);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Query compute device parameters.
		///   Instance represents: Compute device handle.
		/// </summary>
		/// <param name="genParamName">Name of the parameter to query. Default: "buffer_cache_capacity"</param>
		/// <returns>Value of the parameter.</returns>
		// Token: 0x060003B4 RID: 948 RVA: 0x00016304 File Offset: 0x00014504
		public HTuple GetComputeDeviceParam(string genParamName)
		{
			IntPtr proc = HalconAPI.PreCall(296);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Set parameters of an compute device.
		///   Instance represents: Compute device handle.
		/// </summary>
		/// <param name="genParamName">Name of the parameter to set. Default: "buffer_cache_capacity"</param>
		/// <param name="genParamValue">New parameter value.</param>
		// Token: 0x060003B5 RID: 949 RVA: 0x00016354 File Offset: 0x00014554
		public void SetComputeDeviceParam(string genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(297);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamValue);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Set parameters of an compute device.
		///   Instance represents: Compute device handle.
		/// </summary>
		/// <param name="genParamName">Name of the parameter to set. Default: "buffer_cache_capacity"</param>
		/// <param name="genParamValue">New parameter value.</param>
		// Token: 0x060003B6 RID: 950 RVA: 0x000163A0 File Offset: 0x000145A0
		public void SetComputeDeviceParam(string genParamName, string genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(297);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.StoreS(proc, 2, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>Close all compute devices.</summary>
		// Token: 0x060003B7 RID: 951 RVA: 0x000163E4 File Offset: 0x000145E4
		public static void ReleaseAllComputeDevices()
		{
			IntPtr proc = HalconAPI.PreCall(298);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
		}

		/// <summary>
		///   Close a compute_device.
		///   Instance represents: Compute device handle.
		/// </summary>
		// Token: 0x060003B8 RID: 952 RVA: 0x00016408 File Offset: 0x00014608
		public void ReleaseComputeDevice()
		{
			IntPtr proc = HalconAPI.PreCall(299);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>Deactivate all compute devices.</summary>
		// Token: 0x060003B9 RID: 953 RVA: 0x0001643C File Offset: 0x0001463C
		public static void DeactivateAllComputeDevices()
		{
			IntPtr proc = HalconAPI.PreCall(300);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
		}

		/// <summary>
		///   Deactivate a compute device.
		///   Instance represents: Compute device handle.
		/// </summary>
		// Token: 0x060003BA RID: 954 RVA: 0x00016460 File Offset: 0x00014660
		public void DeactivateComputeDevice()
		{
			IntPtr proc = HalconAPI.PreCall(301);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Activate a compute device.
		///   Instance represents: Compute device handle.
		/// </summary>
		// Token: 0x060003BB RID: 955 RVA: 0x00016494 File Offset: 0x00014694
		public void ActivateComputeDevice()
		{
			IntPtr proc = HalconAPI.PreCall(302);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Initialize a compute device.
		///   Instance represents: Compute device handle.
		/// </summary>
		/// <param name="operators">List of operators to prepare. Default: "all"</param>
		// Token: 0x060003BC RID: 956 RVA: 0x000164C8 File Offset: 0x000146C8
		public void InitComputeDevice(HTuple operators)
		{
			IntPtr proc = HalconAPI.PreCall(303);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, operators);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(operators);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Open a compute device.
		///   Modified instance represents: Compute device handle.
		/// </summary>
		/// <param name="deviceIdentifier">Compute device Identifier.</param>
		// Token: 0x060003BD RID: 957 RVA: 0x0001650C File Offset: 0x0001470C
		public void OpenComputeDevice(int deviceIdentifier)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(304);
			HalconAPI.StoreI(proc, 0, deviceIdentifier);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>Get information on a compute device.</summary>
		/// <param name="deviceIdentifier">Compute device handle.</param>
		/// <param name="infoName">Name of Information to query. Default: "name"</param>
		/// <returns>Returned information.</returns>
		// Token: 0x060003BE RID: 958 RVA: 0x00016558 File Offset: 0x00014758
		public static HTuple GetComputeDeviceInfo(int deviceIdentifier, string infoName)
		{
			IntPtr proc = HalconAPI.PreCall(305);
			HalconAPI.StoreI(proc, 0, deviceIdentifier);
			HalconAPI.StoreS(proc, 1, infoName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			return result;
		}

		/// <summary>Get the list of available compute devices.</summary>
		/// <returns>List of available compute devices.</returns>
		// Token: 0x060003BF RID: 959 RVA: 0x000165A0 File Offset: 0x000147A0
		public static HTuple QueryAvailableComputeDevices()
		{
			IntPtr proc = HalconAPI.PreCall(306);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, HTupleType.INTEGER, num, out result);
			HalconAPI.PostCall(proc, num);
			return result;
		}
	}
}
